package cn.evilelf.sort;

import static cn.evilelf.sort.SortUtil.swap;

public class Bubble {
	public static int[] sort(int array[]) {
		for (int i = 1; i < array.length; ++i) {
			for (int j = array.length - 1; j >= i; --j) {
				if (array[j] < array[j - 1]) {
					swap(array, j, j - 1);
				}
			}
		}

		return array;
	}

	public static long[] sort(long array[]) {
		for (int i = 1; i < array.length; ++i) {
			for (int j = array.length - 1; j >= i; --j) {
				if (array[j] < array[j - 1]) {
					swap(array, j, j - 1);
				}
			}
		}

		return array;
	}

	public static float[] sort(float array[]) {
		for (int i = 1; i < array.length; ++i) {
			for (int j = array.length - 1; j >= i; --j) {
				if (array[j] < array[j - 1]) {
					swap(array, j, j - 1);
				}
			}
		}

		return array;
	}

	public static double[] sort(double array[]) {
		for (int i = 1; i < array.length; ++i) {
			for (int j = array.length - 1; j >= i; --j) {
				if (array[j] < array[j - 1]) {
					swap(array, j, j - 1);
				}
			}
		}

		return array;
	}

	@SuppressWarnings("unchecked")
	public static Comparable[] sort(Comparable[] array) {
		for (int i = 1; i < array.length; ++i) {
			for (int j = array.length - 1; j >= i; --j) {
				if (array[j].compareTo(array[j - 1]) < 0) {
					swap(array, j, j - 1);
				}
			}
		}
		return array;
	}

	public static void main(String[] args) {
		String[] array = { "bad", "mum", "fuck", "love", "chuanshiji", "from" };
		// int[] array = { 2, 13, 6, 11, 3, 6 };
		sort(array);
		for (int i = 0; i < array.length; ++i) {
			System.out.println(array[i]);
		}

		// System.out.println("fuck".compareTo("chuanshiji"));
	}
}
